//
//  SubscribeController.swift
//  iPhone
//
//  Created by Toj on 3/28/23.
//
//  本地通知
//

import UIKit

// MARK: - 懒加载(属性), 变量, 初始化init
class SubscribeController: STBaseViewController {
    
    /* subscribeButton */
    private lazy var subscribeButton: UIButton = {
        let view = UIButton()
        view.setTitleColor(.black, for: .normal)
        view.setTitle("发送消息", for: .normal)
        view.addTarget(self, action: #selector(didTapAddSubscribe), for: .touchUpInside)
        return view
    }()
}

// MARK: - 生命周期
extension SubscribeController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMakeInitialize()
        setupMakeAddSubviews()
        setupMakeLayoutSubviews()
    }
}

// MARK: - 点击事件
@objc private extension SubscribeController {
    
    func didTapAddSubscribe() {
        let timeInterval: TimeInterval = 1
        let subscribeId = "51q3\(timeInterval)qwe\(arc4random_uniform(100))"
        let title    = "移动设备"
        let subtitle = "苹果14"
        let body     = "很牛逼的处理器, 不一样的体验哦"
        let userInfo: [String: Any] = ["name": "toj", "imageURL": "https://baidu.com/567", "isShowAlert": (arc4random_uniform(2) == 1 ? true : false)]
        
        UNUserNotificationCenter.current().nf_addSubscribe(id: subscribeId, title: title, subtitle: subtitle, body: body, userInfo: userInfo, timeInterval: timeInterval) { error in
            let localizedDescription = error?.localizedDescription ?? "success"
            print("-->toj: \(localizedDescription)")
        }
    }
}

// MARK: - 初始化设置
private extension SubscribeController {
    
    func setupMakeAddSubviews() {
        view.addSubview(subscribeButton)
    }
    
    func setupMakeLayoutSubviews() {
        subscribeButton.snp.makeConstraints { make in
            make.center.equalTo(view)
            make.width.equalTo(100)
            make.height.equalTo(44)
        }
    }
    
    func setupMakeInitialize() {
        view.backgroundColor = .random
    }
}
